package com.ap.core.webservice.managerefund;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;

import com.ap.core.business.routing.service.api.EndPointRoutingService;
import com.ap.core.cxf.jaxb.common.APCORE1FaultDetailsType;
import com.ap.core.cxf.jaxb.managerefund.RefundMsgType;
import com.ap.core.cxf.jaxb.managerefund.RequestRetrieveRefundAccount;
import com.ap.core.cxf.jaxb.managerefund.ResponseRetrieveRefundAccount;
import com.ap.core.cxf.jaxb.managerefund.RoutingInfoType;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.info.BaseMessageInfo;
import com.ap.core.message.info.RequestMessageInfo;
import com.ap.core.message.service.CoreResponseInfo;
import com.ap.core.webservice.BaseWSService;
import com.core.ap.wsdl.managerefundservice_1.ManageRefund1PortType;
import com.core.ap.wsdl.managerefundservice_1.RetrieveRefundAccount1Fault;

/**
 * Implementation class for {@link com.core.ap.wsdl.managerefundservice_1.ManageRefund1PortType}
 */
public class ManageRefundWebServiceImpl<AI> extends BaseWSService<RequestMessageInfo<RefundMsgType>, BaseMessageInfo,AI> implements ManageRefund1PortType {

	private EndPointRoutingService<RoutingInfoType> endPointRoutingService;

	@Override
	@WebResult(name = "RetrieveRefundAccount_1Response", targetNamespace = "http://ap.core.com/xsd/managerefunddata_1", partName = "retrieveRefundAccount_1Response")
	@WebMethod(operationName = "retrieveRefundAccount_1", action = "retrieveRefundAccount_1")
	public ResponseRetrieveRefundAccount retrieveRefundAccount1(
			@WebParam(partName = "retrieveRefundAccount_1Request", name = "RetrieveRefundAccount_1Request", targetNamespace = "http://ap.core.com/xsd/managerefunddata_1") RequestRetrieveRefundAccount retrieveRefundAccount1Request)
			throws RetrieveRefundAccount1Fault {
		 LOG.info("Starting processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + retrieveRefundAccount1Request.getMsgHdr().getMsgType().name());
        CoreResponseInfo<BaseMessageInfo, AI> coreResponseInfo;
        ResponseRetrieveRefundAccount responseRetrieveRefundAccount = null;
		 try {
             coreResponseInfo =  messageProcessor.process(retrieveRefundAccount1Request, new ResponseRetrieveRefundAccount());
             responseRetrieveRefundAccount = (ResponseRetrieveRefundAccount)coreResponseInfo.getResponse();
             RoutingInfoType routingInfo = endPointRoutingService.getEndPointRoutingInfo(responseRetrieveRefundAccount.getRefundAcctDetails().getFIId(), retrieveRefundAccount1Request.getMsgHdr().getMsgType().name());

			 responseRetrieveRefundAccount.setRoutingInfo(routingInfo);
	        } catch (BusinessFailureException e) {
	            final APCORE1FaultDetailsType retrieveRefundFault = buildSOAPFaultType(retrieveRefundAccount1Request.getMsgHdr().getMsgType().name(), retrieveRefundAccount1Request.getMsgHdr().getMsgId(), e);
	        	throw new RetrieveRefundAccount1Fault(getFaultString(retrieveRefundAccount1Request.getMsgHdr().getMsgType().name(), retrieveRefundAccount1Request.getMsgHdr().getMsgId()), retrieveRefundFault);            
	        }
	        LOG.info("Finishing processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + retrieveRefundAccount1Request.getMsgHdr().getMsgType().name());
		return (ResponseRetrieveRefundAccount)coreResponseInfo.getResponse();
	}

	public void setEndPointRoutingService(
			EndPointRoutingService<RoutingInfoType> endPointRoutingService) {
		this.endPointRoutingService = endPointRoutingService;
	}
}
